package com.wd.health.view.activity.mine;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;
import com.wd.health.R;
import com.wd.health.model.bean.DqwzBean;
import com.wd.health.model.bean.StopBean;
import com.wd.health.utils.RetrofitManager;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class DqwzActivity extends AppCompatActivity {

    private ImageView img_back;
    private SimpleDraweeView sdv_yisheng_datu;
    private TextView tv_dqwz_name;
    private TextView tv_dqwz_zhiwei;
    private TextView tv_dqwz_keshi;
    private int doctorId;
    private int recordId;
    private Button btn_stop;
    private String URl = "http://mobile.bwstudent.com/images/health/doctor/system_image_pic/system_image5.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dqwz);
        initView();
        initData();
        initStop();
        initSdv();
    }

    private void initStop() {
        btn_stop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RetrofitManager.getInstance().putStopData(recordId, new Observer<StopBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(StopBean stopBean) {
                        if (stopBean.getMessage().equals("结束问诊成功")){
                            Toast.makeText(DqwzActivity.this, "已结束", Toast.LENGTH_SHORT).show();
                            finish();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
            }
        });
    }

    private void initSdv() {
        sdv_yisheng_datu.setImageURI(URl);
    }

    private void initData() {
        RetrofitManager.getInstance().getDqwzData(new Observer<DqwzBean>() {

            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DqwzBean dqwzBean) {
                if (dqwzBean.getMessage().equals("当前无问诊")){
                    Toast.makeText(DqwzActivity.this, "当前无问诊", Toast.LENGTH_SHORT).show();
                }else {
                    DqwzBean.ResultBean result = dqwzBean.getResult();
                    String doctorName = result.getDoctorName();
                    String department = result.getDepartment();
                    String jobTitle = result.getJobTitle();
                    long inquiryTime = result.getInquiryTime();
                    recordId = result.getRecordId();
                    doctorId = result.getDoctorId();
                    tv_dqwz_name.setText(doctorName);
                    tv_dqwz_zhiwei.setText(jobTitle);
                    tv_dqwz_keshi.setText(department);
                }
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });

    }

    private void initView() {
        img_back = findViewById(R.id.img_back);
        sdv_yisheng_datu = findViewById(R.id.sdv_yisheng_datu);

        tv_dqwz_name = findViewById(R.id.tv_dqwz_name);
        tv_dqwz_zhiwei = findViewById(R.id.tv_dqwz_zhiwei);
        tv_dqwz_keshi = findViewById(R.id.tv_dqwz_keshi);
        btn_stop = findViewById(R.id.btn_stop);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


}